package main

import "fmt"

func main() {

	var age int = 25

	func() {

		fmt.Println("aaa")
	}()

	func() {

		fmt.Println("age is :", age)

		age++

	}()

	fmt.Println("age is :", age)

	fff := closure(age)

	fmt.Println(fff())

	fmt.Println(age)

	fmt.Println(fff())

	fmt.Println(age)

	fmt.Println(fff())

	fmt.Println(age)

	fmt.Println(fff())

	fmt.Println(age)

}

func closure(age int) func() (age int) {

	//age++

	// 闭包还在使用age变量 将一直持有
	return func() (res int) {

		fmt.Println(age)

		age++

		res = age * age

		return
	}
}
